package net.minecraft.src;

public class EntityMesothelae extends EntityPPHCreature
{

	public EntityMesothelae(World world)
	{
		super(world);
		texture = "/pph/mob/mesothelae.png";
		attackStrength = 4;
	}
	
	public int getMaxHealth()
    {
        return 16;
    }
	
	public void func_35112_o() //makes immune to effects of web block
    {
    }
	
	public boolean getCanSpawnHere()
    {
        int i = MathHelper.floor_double(posX);
        int j = MathHelper.floor_double(boundingBox.minY);
        int k = MathHelper.floor_double(posZ);
        return getBlockPathWeight(i, j, k) >= 0.0F && worldObj.difficultySetting > 0;
    }
	
	protected void updateEntityActionState()
    {
		if(!worldObj.multiplayerWorld && worldObj.difficultySetting == 0)
        {
            setEntityDead();
        }
    }	
	
	public void onUpdate()
	{
		//Updating Delays, etc
		/**/if(entityToAttack.isDead)
		/**/	entityToAttack = null;
		/**/if(entityToAttack.getDistanceSq(posX, posY, posZ) > 10F)
		/**/	entityToAttack = null;
		if(attackTime > 0)
			--attackTime;
		
		//AI
		if(entityToAttack == null)
		{
			EntityLiving ent = getClosestEntity(posX, posY, posZ, 5D);
			if(ent != null)
			{
				entityToAttack = ent;
				newX();
				newY();
				newZ();
			}
		}
		else if(entityToAttack.getDistanceSq(posX, posY, posZ) < 0.5F)
		{
			attackEntityAsMob(entityToAttack);
			attackTime = 20;
		}
		super.onUpdate();
	}

    public EntityLiving getClosestEntity(double d, double d1, double d2, double d3)
    {
        double d4 = -1D;
        EntityLiving entityplayer = null;
        for(int i = 0; i < worldObj.playerEntities.size(); i++)
        {
            EntityLiving entityplayer1 = (EntityLiving)worldObj.playerEntities.get(i);
            double d5 = entityplayer1.getDistanceSq(d, d1, d2);
            if((d3 < 0.0D || d5 < d3 * d3) && (d4 == -1D || d5 < d4))
            {
                d4 = d5;
                entityplayer = entityplayer1;
            }
        }
        for(int i = 0; i < worldObj.loadedEntityList.size(); i++)
        {
        	EntityLiving entityplayer1 = (EntityLiving)worldObj.loadedEntityList.get(i);
            double d5 = entityplayer1.getDistanceSq(d, d1, d2);
            if((d3 < 0.0D || d5 < d3 * d3) && (d4 == -1D || d5 < d4))
            {
                d4 = d5;
                entityplayer = entityplayer1;
            }
        }
        return entityplayer;
    }
    
    protected void newX()
    {
    	if(entityToAttack == null)
    		super.newX();
    	else
    		randomX = (int)entityToAttack.posX;
    }
    
    protected void newZ()
    {
    	if(entityToAttack == null)
    		super.newZ();
    	else
    		randomZ = (int)entityToAttack.posZ;
    }
    
    protected void newY()
    {
    	if(entityToAttack == null)
    		randomY = (int)posY;
    	else
    		randomY = (int)entityToAttack.posY;
    	
    }

	protected String getLivingSound()
	{
		return "mob.spider";
	}

	protected String getHurtSound()
	{
		return "mob.spider";
	}

	protected String getDeathSound()
	{
		return "mob.spiderdeath";
	}

	protected int getDropItemId()
    {
        return mod_pph.fang.shiftedIndex;
    }
	
	protected void dropFewItems(boolean flag, int i)
    {
        int j = rand.nextInt(i);
        for(int k = 0; k < j; k++)
        {
            dropItem(mod_pph.fang.shiftedIndex, 1);
        }

        j = rand.nextInt(3 + i);
        for(int l = 0; l < j; l++)
        {
            dropItem(Item.silk.shiftedIndex, 1);
        }

    }
	
	protected int getDropItemQuantity()
	{
		return 1;
	}
	
	/* Agressive */
	EntityLiving entityToFace;

}